require(["common", "jQuery", "coAjax"], function(jSouper, $, coAjax) {
	//百度地图
	var ak_key = "E1c20826ad9c3bccec028cfb9ee17feb";
	var doc_write = document.write;
	var doc_s_write = function(HTML) {
		var dom = $("<div>" + HTML + "</div>");
		console.log(HTML);
		dom.find("script[src]").each(function(i, scriptNode) {
			scriptNode.src && require([scriptNode.src]);
			scriptNode.removeAttribute("src")
		});
		dom.appendTo(document.body);
	}
	document.write = doc_s_write;
	require(["http://api.map.baidu.com/api?v=2.0&ak=" + ak_key], function(scriptText) {
		document.write = doc_write;
		var _BMap_ti = setInterval(function() {
			if (window.BMap) {
				clearInterval(_BMap_ti);
				init_map();
			}
		})
	});

	function init_map() {
		// 百度地图API功能
		var map = new BMap.Map("map"); // 创建Map实例
		// map.centerAndZoom(new BMap.Point(X, Y), 9);     // 初始化地图,设置中心点坐标和地图级别，数字越大，缩放比例越大
		map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
		map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
		// map.addControl(new BMap.OverviewMapControl());              //添加缩略地图控件
		map.enableScrollWheelZoom(); //启用滚轮放大缩小
		// map.addControl(new BMap.MapTypeControl());          //添加地图类型控件
		// map.setCurrentCity("福州");          // 设置地图显示的城市 此项是必须设置的

		var local = new BMap.LocalSearch(map, {
			renderOptions: {
				map: map
			}
		});
		var _search_ti;
		_search_ti = setInterval(function() {
			var address = App.get("bus_info.info.address")
			if (address) {
				local.search(address);
				clearInterval(_search_ti);
			}
		})
	};

	if (App.get('bus_info.info.open_time.s_min') < 10) {
		App.set('bus_info.info.open_time.s_min', '0' + App.get('bus_info.info.open_time.s_min'));
	};
	if (App.get('bus_info.info.open_time.e_min') < 10) {
		App.set('bus_info.info.open_time.e_min', '0' + App.get('bus_info.info.open_time.e_min'));
	};

	App.set('$Event.showStoreImg', function(e, vm) {
		console.log(vm.get("href"));
		vm.set("$Private.aa", "sdads");
		if (App.get('imgPrivate')) {
			App.set('imgPrivate', '');
		} else {
			App.set('imgPrivate', 'focus');
		}
	});
	App.set('$Event.showBigImg', function(e, vm) {
		console.log(vm.get('$Index'));
		vm.model.toggle('iPrivate');
		App.model.toggle('blockimg');
	})
});